import {
	baseUrl
} from './baseUrl.js'
module.exports = (vm) => {
	// 初始化请求配置
	uni.$u.http.setConfig((config) => {
		/* config 为默认全局配置*/
		config.baseURL = baseUrl;
		// config.header['Authorization'] = '563492ad6f9170000100000146f7f6eab0344382944deed634ae4344';
		return config;
	})

	// 请求拦截
	uni.$u.http.interceptors.request.use((config) => {
		// 初始化请求拦截器时，会执行此方法，此时data为undefined，赋予默认{}
		config.data = config.data || {};
		// if (!config.header['Authorization']) {
		// 	config.header['Authorization'] = '563492ad6f9170000100000146f7f6eab0344382944deed634ae4344';
		// };
		return config;
	}, config => {
		return Promise.reject(config);
	})

	// 响应拦截
	uni.$u.http.interceptors.response.use((response) => {
		const data = response.data
	    if(data.msg === 'success') return data === undefined ? {} : data.res;
	}, (response) => {
		return Promise.reject(response)
	})
}
